﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Text.RegularExpressions;
using ElectronicWMSA.Comm.ClassFiles;
using SYDZ.WMS.DBUtility;
using Sample;
using System.Data.SqlClient;
using System.Drawing.Drawing2D;

namespace ElectronicWMSA.Warehouse
{
    public partial class List_PickingFrm1 : Form
    {

        public List_PickingFrm1()
        {
            InitializeComponent();

        }
        #region 按esc关闭窗体
        //重写ProcessCmdKey的方法

        protected override bool ProcessCmdKey(ref System.Windows.Forms.Message msg, System.Windows.Forms.Keys keyData)
        {

            int WM_KEYDOWN = 256;

            int WM_SYSKEYDOWN = 260;

            if (msg.Msg == WM_KEYDOWN | msg.Msg == WM_SYSKEYDOWN)
            {

                switch (keyData)
                {

                    case Keys.Escape:

                        this.Close();//esc关闭窗体

                        break;

                }



            }

            return false;

        }
        #endregion

        private void List_PickingFrm1_Load(object sender, EventArgs e)
        {
            Getdata();
        }
        private void Getdata()
        {
            dataGridView1.DataSource = null;
            string sql = "select  * from  Vlh_KB  where  BH_Date between '" + DateTime.Now.AddDays(-1).ToString("yyyyMMdd") + "' and  '" + DateTime.Now.AddDays(4).ToString("yyyyMMdd") + "'  ";
            DataTable dt = DbHelperSQL.ExecuteDataTable(sql);
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = dt;
        }
    
        public class UserInfo
        {
            public string machine { get; set; }
            public string jh { get; set; }
            public string sj { get; set; }
            public string jd { get; set; }
            public int Press { get; set; }
            public Color color { get; set; }

            //进度条图片属性
            public Image PressImg
            {
                get
                {
                    Bitmap bmp = new Bitmap(104, 30); //这里给104是为了左边和右边空出2个像素，剩余的100就是百分比的值
                    Graphics g = Graphics.FromImage(bmp);
                    g.Clear(Color.White); //背景填白色

                    //g.FillRectangle(Brushes.Red, 2, 2, this.Press, 26);  //普通效果
                    //填充渐变效果
                    g.FillRectangle(new LinearGradientBrush(new Point(2, 2), new Point(30, 30), this.color, this.color), 2, 2, this.Press, 26);
                    return bmp;
                }
            }
        }
        private string getmachine = "";
        private void sbstring()
        {

            //string[] arr = { "PT-RZ570BD", "PT-LB303", "TH-70LF50ER", "ET-PNT100", "TH-80LF50ER", "PT-EZ770ZE" };
            //int index = new Random().Next(0, arr.Length); //生成随机下标
            //getmachine = arr[index];  //取值
            string sql = "  select top 1 Product_Model FROM dbo.T_PickStockPrepare  order by NID desc ";
            object obj = DbHelperSQL.GetSingle(sql);
            getmachine = Convert.ToString(obj == null ? "" : obj);
        }
        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            dataGridView1.Columns[6].DefaultCellStyle.BackColor = Color.FromArgb(31, 78, 120);
        
        }

        private void dataGridView1_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
            if (e.RowIndex < 0)
                return;

            DataGridViewRow dgr = dataGridView1.Rows[e.RowIndex];
            try
            {
                if (e.ColumnIndex == 6)//定位到第6列，如不定位到具体的哪列，则整行的颜色改变  
                {

                    if (Convert.ToDouble(dgr.Cells["wc"].Value.ToString()) < 40)//dgr.Cells["Column4"]为需要判断的列Name，而不是HeadText  
                    {
                        e.CellStyle.ForeColor = Color.Red;//将前景色设置为红色，即字体颜色设置为红色  
                        e.CellStyle.Font = new Font("微软雅黑", 12, FontStyle.Bold);
                        // e.CellStyle.BackColor = Color.Green;//将背景色设置为绿色，即列的颜色设置为红色  
                    }
                    else if (Convert.ToDouble(dgr.Cells["wc"].Value.ToString()) >= 40 && Convert.ToDouble(dgr.Cells["wc"].Value.ToString()) < 90)
                    {
                        e.CellStyle.ForeColor = Color.Yellow;//将前景色设置为红色，即字体颜色设置为红色  
                        e.CellStyle.Font = new Font("微软雅黑", 12, FontStyle.Bold);
                    }
                    else if (Convert.ToDouble(dgr.Cells["wc"].Value.ToString()) >= 100)
                    {
                        e.CellStyle.ForeColor = Color.White;//将前景色设置为红色，即字体颜色设置为红色  
                        e.CellStyle.Font = new Font("微软雅黑", 12, FontStyle.Bold);
                    }
                    else
                    {
                        e.CellStyle.ForeColor = Color.LightPink;//将前景色设置为红色，即字体颜色设置为红色  
                        e.CellStyle.Font = new Font("微软雅黑", 12, FontStyle.Bold);
                    }
                }
           
                //  MessageBox.Show("随机获取的值是：" + str);
                if (dgr.Cells["BH_Machine"].Value.ToString() == getmachine)//dgr.Cells["Column4"]为需要判断的列Name，而不是HeadText  
                {
                    e.CellStyle.BackColor = Color.Green;
                    e.CellStyle.ForeColor = Color.White;
                }

            }
            catch
            {

            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            sbstring();
            Getdata();
        }
    }
}
